/**
 * Created by Administrator on 2017/4/5.
 */
var key = getCookie('key');
if(!key){
    window.location.href = WapSiteUrl+'/tmpl/member/login.html';
}
if(key==''){
     window.location.href = "login.html";
}else {

    var pageUrl = ApiUrl+"/index.php?act=store&op=vr_order_list";

    init();

    function init(){
            $.ajax({
            type:"GET",
            url:ApiUrl+"/index.php?act=store&op=vr_order_list",
            data:{key:key},
            dataType:"json",
            success:function(res){
                if (res){
                    $('.main').html(template.render('list',res));
                }else{
                    $('.main').html("<p class='no-data'>赞无数据</p>");
                }
            }
        })
    }

    function tab(num) {
        $('.nav-item a').removeClass('active');
        $('.nav-item a').eq(num).addClass('active');
        var url = ApiUrl+"/index.php?act=store&op=vr_order_list&use_state="+num;
        pageUrl = url;
        $.ajax({
            type:"GET",
            url:url,
            dataType:"json",
            success:function(res){
                if (res){
                    $('.main').html(template.render('list',res));
                }else{
                    $('.main').html("<p class='no-data'>赞无数据</p>");
                }
            }
        })
    }

    var isLock = false;
    var page = 1;
    /**
     * 下拉到底刷新
     */
    $(window).scroll(function () {
        var windowheight=$(window).height();//窗口高度
        var scrolltop=$('body').scrollTop();//滚动条高度
        var eh=$(document).height();//文本高度
        if(parseInt(windowheight+scrolltop+1)>=eh && isLock==false){
            document.getElementsByClassName('list_loading')[0].style.display =' block';
            isLock = true;
            page+=1;
            // 获取订单信息
            $.ajax({
                type:"GET",
                url:pageUrl+"&page="+page,
                dataType:"json",
                success:function(res){
                    document.getElementsByClassName('list_loading')[0].style.display =' none';
                    isLock = false;
                    if (res){
                        $('.main').html($('.main').html()+template.render('list',res));
                    }else{
                        $('.no-data').show();
                    }
                }
            })

        }
    })
    function calcRem() {
        var http = document.getElementsByTagName("html")[0];
        var w = document.documentElement.clientWidth;
        http.style.fontSize = w / 50 + "px";
    }
    calcRem();
    window.onresize = function() {
        calcRem();
    };

    window.onscroll = function () {
        var seeHeight = document.documentElement.clientHeight;
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        var h = document.body.scrollHeight; //文本高度

        if (seeHeight + scrollTop == h) {
            $('.loading').show();
            $('.main_center').append(text);
        }
    };
    $('.main_top p').on("touchstart", function () {
        $(this).addClass('active').siblings().removeClass('active');
    })
}